<template>
  <div>
    <h1 style="color: #ea3200;position: relative;">欢迎注册</h1>
    <h2 style="color: #ea3200;position: relative;">Welcome to Student Book Store</h2>
    <el-card class="box-card" style=";padding: 0;text-align: center">
      <div style="width: 380px;height: 500px;margin-left: 37%">
        <img src="/images/reg_logo.jpg.jpg" alt="" title="欢迎来到学子书城" style="width: 150px;margin-left: 105px">
        <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm"
                 style="position: relative;">
          <el-form-item label="用户名" prop="username">
            <el-input v-model="ruleForm.username"></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input type="password" v-model="ruleForm.password" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="手机号" prop="phoneNum">
            <el-input v-model="ruleForm.phoneNum"></el-input>
          </el-form-item>
          <el-form-item label="验证码" prop="checkCode" style="width: 250px">
            <el-input v-model="check.checkCode"></el-input>
          </el-form-item>
          <el-button class="button" type="primary" style="position: absolute;top:185px;left: 250px;width: 130px"
                     @click="getCode()">获取验证码
          </el-button>
          <el-form-item>
            <el-button class="button" type="primary" @click="submitForm('ruleForm')">注册</el-button>
            <el-button @click="resetForm('ruleForm')">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <a href="/">我已经有账号了。</a>
    </el-card>
    <p>Copyright © 2015-2022 学子书城电子商务有限责任公司 版权所有</p>
  </div>
</template>
<style>
.button {
  background-color: #ea3200;
  border: none;
}
.button:hover{
  background-color: #ea7479;
}
.button:focus{
  background-color: #ea7479;
}

</style>
<script>
export default {
  data() {
    return {
      check: {checkCode: ''},
      getCheck: {getCode: ''},
      ruleForm: {
        username: '',
        password: '',
        phoneNum: '',

      },
      rules: {
        username: [
          {required: true, message: '请输入用户名', trigger: 'blur'},
          {min: 4, max: 18, message: '长度在 6 到 18 个字符', trigger: 'blur'},
          {pattern: /^[a-zA-Z]\w{5,17}$/, message: '必须以字母开头,只能包含字符,数字的6-18位字符。'}
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'},
          {pattern: /^[A-Za-z0-9]{6,12}$/, message: "必须是英文或者数字，并且长度为6-12个字符"}
        ],
        phoneNum: [
          {required: true, message: '请输入手机号', trigger: 'blur'},
          {pattern: /^[1][3,4,5,7,8][0-9]{9}/, message: '请输入正确的手机号'},
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.check.checkCode==this.getCheck.getCode){
              console.log("信息正确功能还没做")
          }else {
            console.log("获得到的验证码"+this.getCheck.getCode)
            console.log("输入的验证码"+this.check.checkCode)
            this.$message.error("验证码错误！")
          }

        } else {
          this.$message.error("请检查您的输入信息！")
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    getCode() {
      let url="http://localhost:9080/SMS/check";
      this.axios.get(url+"?phoneNum="+this.ruleForm.phoneNum).then((response) => {
        this.getCheck.getCode = response.data.data
        console.log(response)
      })
    }
  }
}
</script>

<style scoped>

</style>